package com.fans.utils;

import java.io.IOException;

import javax.servlet.http.HttpServletResponse;
/**
 * 把对象转成json格式字符串返回
 * @author fanhaohao
 *
 */
public class WriterUtil {
	public static String writer(HttpServletResponse response,Object object){
		return writer(response, JsonMapper.toJsonString(object), "application/json;charset=UTF-8");
	}
	protected static String writer(HttpServletResponse response, String string, String type) {
		try {
			response.setContentType(type);
			response.setCharacterEncoding("utf-8");
			response.getWriter().print(string);
			return null;
		} catch (IOException e) {
			return null;
		}
	}
}
